/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number[]}
 * hash表，空间复杂度O(n) 
 */
var twoSum = function(nums, target) {
  let hash = {};
  let result = [];
  for (let i = 0; i < nums.length; i++) {
    const element = nums[i];
    // if(element > target) {
    //   continue;
    // }
    console.log(hash[target - element], target - element)
    if(hash[target - element] !== undefined) {
      result = [hash[target - element], i];
      break;
    }
    hash[element] = i;
  }
  console.log(hash)
  return result;
};
console.log(twoSum([3,4,5,4,7,8,1], 12));

// console.log(Math.sqrt(3))